package com.backedserver.global;

import com.common.global.BizException;
import com.common.global.JwtTokenException;
import com.common.utils.ResultVoUtil;
import com.common.vo.ResultVo;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author johnny
 * @create 2021-05-14 3:47 下午
 **/
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(value = JwtTokenException.class)
    public ResultVo loginFail(JwtTokenException e) {
        System.out.println("未知异常！原因是:" + e);
        return ResultVoUtil.error(Integer.valueOf(e.getErrorCode()), e.getErrorMsg());
    }

    @ExceptionHandler(value = BizException.class)
    public ResultVo loginFail(BizException e) {
        System.out.println("业务异常！原因是:" + e);
        return ResultVoUtil.error(Integer.valueOf(e.getErrorCode()), e.getErrorMsg());
    }
}